home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Initialising structure members - help please!
- Date: Tue, 20 Feb 96 22:04:56 GMT
- Organization: none
- Message-ID: <824853896snz@genesis.demon.co.uk>
- References: <4gb8hn$3m8@news.mistral.co.uk> <31298EF1.5F2C@cmt.lpr.mail.carel.fi> <4gckb1$77e@news.mistral.co.uk>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4gckb1$77e@news.mistral.co.uk>
- mikebarnard@mistral.co.uk "Mike Barnard" writes:
-
- >Thanks, I'll look at what this means. But as a learning question, (not
- >an argumentative one!!!), why does this good old boy work then?
- >
- >char name[]="An array of characters";
-
- This can also be written as:
-
- char name[]= { "An array of characters" };
-
- C permits this as a special case for character array initialisation. Note
- the word 'initialisation' - this isn't an assignment. It is equivalent to:
-
- char name[] = {
- 'A', 'n', ' ', 'a', 'r', 'r', 'a', 'y', ' ', 'o', 'f', ' ',
- 'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r', 's', '\0'
- };
-
- >Surely "name" is an array of characters as is my "description"? It
- >works here. Doesn't it? This leads me on to another question actually,
-
- You can initialise arrays when you define them, but you can't assign to
- them afterwards (just to their elements where appropriate).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-